def pr(n):    c = True
for d in range(2, int(n ** 0.5) + 1):     
   if n % d == 0:
      c = False 
   break
return c    
 cn = int(input())if len(str(n)) != 4:
   print("0")
   exit()
   numbs = []
ans = []
n1 = n // 1000 
n2 = n // 100 % 10
n3 = n // 10 % 10
n4 = n % 10
numbs = [n1, n2, n3, n4, n1 * 10 + n2,  n2 * 10 + n3, n3 * 10 + n4, n1 * 100 + n2 * 10 + n3, n2 * 100 + n3 * 10 + n4, n]
for x in numbs:
   if pr(x):        ans.append(x)
if ans:    print(max(ans))
else:    print("0")